<template>
  <div class="_wz_cent_main _wz_unread">
    <Card dis-hover :bordered="true" style="margin:0 0 10px;">
      <p slot="title">搜索</p>
      <Form ref="formSearch" :model="formDataSearch" label-position="right" :label-width="120" inline>
        <FormItem label="从业人员">
          <i-input v-model="formDataSearch.driverName" placeholder="请填写从业人员" clearable />
        </FormItem>
        <FormItem label="联系电话">
          <i-input v-model="formDataSearch.driverPhone" placeholder="请填写联系电话" clearable />
        </FormItem>
        <FormItem label="参会状态">
          <i-select v-model="formDataSearch.remoteState" filterable placeholder="请选择参会状态" clearable>
            <Option value="0">未参会</Option>
            <Option value="1">已参会</Option>
          </i-select>
        </FormItem>
        <FormItem label="身份证号">
          <i-input v-model="formDataSearch.driverIdentify" placeholder="请填写身份证号" clearable />
        </FormItem>
        <FormItem label="从业类型">
          <i-select v-model="formDataSearch.driverType" filterable placeholder="请选择从业类型" clearable>
            <Option v-for="item in personType" :value="item.code" :key="item.code">{{item.value}}</Option>
          </i-select>
        </FormItem>
        <Button type="primary" @click="searchSubmit">搜索</Button>
      </Form>
    </Card>
    <Card dis-hover :bordered="true" style="height: 100%;">
      <p slot="title">列表</p>
      <wzTbale ref="wzTbale" :tableData="tableData"></wzTbale>
    </Card>

    <Spin size="large" fix v-if="spinShow"></Spin>

  </div>
</template>
<script>

import wzTbale from "../../../components/table/table";

export default {
  props: ['formDetailsData'],//接收来自父组件的数据
  components: {
    wzTbale,//列表
  },
  data() {
    return {
      personType: [],//从业类型
      spinShow:false,//本页加载
      formDataSearch: {recordUuid:this.formDetailsData.uuid},//搜索表单数据
      tableData: {
        url: this.apiUrl.webApi + "/safety/meeting/meetingRecordRemoteList",//请求地址
        method: 'post',//请求方式
        where: {recordUuid:this.formDetailsData.uuid},//搜索条件
        height: '100%',//表格高度 auto
        page: false,//分页是否使用
        columns: [//表头数据
          {type: 'index', width: 70, align: 'center', title: '序号'},
          {title: '从业人员', minWidth: 100, key: 'remoteDriverName'},
          {title: '从业类型', minWidth: 120, key: 'remoteDriverTypeName'},
          {title: '身份证号', minWidth: 160, key: 'remoteDriverIdentifyNum'},
          {title: '联系电话', minWidth: 130, key: 'remoteDriverPhone'},
          {
            title: '参会状态', minWidth: 140, render: (h, params) => {
              //  0：未开始，1：已完成，-1：进行中
              if (params.row.remoteState == 1) {
                return h('Tag', {props: {type: 'dot',color: 'success'}}, '已参会')
              } else {
                return h('Tag', {props: {type: 'dot',color: 'warning'}}, '未参会')
              }
            }
          },
          {
            title: '操作', fixed: 'right', width: 80,
            render: (h, params) => {
              let operationButtons = [];
              operationButtons.push(h('span', {
                style: {"color": "#2d8cf0", "cursor": "pointer"},
                on: {
                  click: () => {
                    var that = this;
                    that.$Modal.confirm({
                      title: '移除提醒',
                      content: '确定要移除选中的记录？',
                      onOk: () => {
                        that.spinShow = true;
                        that.axios.post(that.apiUrl.webApi + "/safety/meeting/meetingRecordRemoteRemove", {uuid: params.row.uuid,driverUuid:params.row.remoteDriverUuid}).then(res => {
                          if (!!res) {
                            that.axios.post(that.apiUrl.webApi + "/safety/meeting/meetingRefresh" ,{uuid:that.formDetailsData.uuid}).then(res => {
                              if (!!res) {
                                that.spinShow = false;
                                that.$Message.success('移除成功.');
                                that.$emit("searchSubmit")
                                that.$refs.wzTbale.tableLoadData();
                              }
                            }).catch(err => {
                              console.log("失败", err)
                            })


                          }
                        }).catch(err => {
                          console.log("失败", err)
                        })
                      },
                      onCancel: () => {
                        //点击取消
                      }
                    });
                  }
                }
              }, '移除'))
              return operationButtons;
            }
          }
        ],
        format: {//返回数据格式
          list: ['data'],//数据list
        },
      },
    }
  },
  beforeCreate() {//beforeCreate创建前状态

  },
  created() {//created创建完毕状态
  },
  beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

  },
  mounted() {//mounted 挂载结束状态
    let that = this;

    //从业类型
    that.axios.post(that.apiUrl.systemDictSystemDictList, {type: 'person_type'}).then(res => {
      if (!!res) {
        that.personType = res.data.data;
      }
    }).catch(err => {
      console.log('失败', err);
    })
  },
  methods: {//执行的方法
    searchSubmit() {//搜索
      this.tableData.where = JSON.parse(JSON.stringify(this.formDataSearch));
      this.$refs.wzTbale.tableLoadData(true);
    },

  },
  watch: {//监听

  },
  beforeUpdate() {//beforeUpdate 更新前状态

  },
  updated() {//updated 更新完成状态

  },
  beforeDestroy() {//beforeDestroy 销毁前状态

  },
  destroyed() {//destroyed 销毁完成状态

  }
}
</script>
<style lang="less">
._wz_unread {
  height: 100%;
  display: flex;
  flex-direction: column;
  .ivu-card-body {
    height: calc(100% - 51px);
  }
}
</style>
